﻿using System;
using System.Web;
using System.IO;

namespace VLUNewsUI.VLUNews
{
    public class FileUploadHandler : IHttpHandler 
    {
        public void ProcessRequest(HttpContext context)
        {
            string fileName = HttpContext.Current.Request.QueryString["FileName"].ToString();
            using (FileStream fs = File.Create(context.Server.MapPath(Path.Combine("~/App_Data/", "test.png")) + fileName))
            {
                Byte[] buffer = new Byte[32 * 1024];
                int read = context.Request.GetBufferlessInputStream().Read(buffer, 0, buffer.Length);
                while (read > 0)
                {
                    fs.Write(buffer, 0, read);
                    read = context.Request.GetBufferlessInputStream().Read(buffer, 0, buffer.Length);
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}